
import java.util.Scanner;

class QNode<E> {
    E data;
    QNode<E> next;

    public QNode() {

    }

    public QNode(E data) {
        super();
        this.data = data;
        this.next = null;
    }

}

class LinkQueue<E> {
    QNode<E> front;
    QNode<E> rear;

    /* 请在这里填写答案 */
    LinkQueue() {
        front = rear = null;
    }

    boolean isEmpty() {
        return front == null;
    }

    E GetHead() {
        if (isEmpty())
            throw new IllegalArgumentException("空");
        else {
            return (E)front.data;
        }
    }

    void EnQueue(E e) {
        QNode<E> newnode = new QNode<E>(e);
        if (isEmpty()) {
            front=rear= newnode;
        } else {
            newnode.next = rear.next;
            rear.next = newnode;
            rear = newnode;
        }
    }

    E DeQueue() {
        if (isEmpty())
            throw new IllegalArgumentException("空");
        else {
            E ret = (E)front.data;
            front = front.next;
            if(front == null)
                rear = null;
            return ret;
        }
    }
}

public class Main4 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        LinkQueue<Integer> Q = new LinkQueue<Integer>();
        int x = sc.nextInt();
        while (x != -1) {
            Q.EnQueue(x);
            x = sc.nextInt();
        }

        System.out.println("Head:");
        try {
            int e = Q.GetHead();
            System.out.println(e);
        } catch (IllegalArgumentException e) {
            System.out.println("NULL");
        }

        System.out.println("Pop:");
        while (!Q.isEmpty()) {
            int e = Q.DeQueue();
            System.out.print(e+" ");
        }
        System.out.println("NULL");
        sc.close();
    }
}
